package com.cpic.rxjava;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class ObserverObserverOn<T> implements  Observer<T> {


    Observer<T> source;
    int threadFlag=0;

    public ObserverObserverOn(Observer<T> source, int threadFlag) {
        this.source = source;
        this.threadFlag = threadFlag;
    }

    @Override
    public void onNext(T t) {
        SchedulerService.INSTANCE.run(new Runnable() {
            @Override
            public void run() {
                source.onNext(t);
            }
        },threadFlag);
    }

    @Override
    public void onError(Throwable throwable) {
        SchedulerService.INSTANCE.run(new Runnable() {
            @Override
            public void run() {
                source.onError(throwable);
            }
        },threadFlag);

    }

    @Override
    public void onSubcribe() {

        SchedulerService.INSTANCE.run(new Runnable() {
            @Override
            public void run() {
                source.onSubcribe();
            }
        },threadFlag);

    }

    @Override
    public void onComplete() {
        SchedulerService.INSTANCE.run(new Runnable() {
            @Override
            public void run() {
                source.onComplete();
            }
        },threadFlag);

    }
}
